package com.ys.controller;

import com.ys.mapper.InventoryMapper;
import com.ys.mapper.InventoryRecordMapper;
import com.ys.pojo.Drugs;
import com.ys.pojo.Inventory;
import com.ys.pojo.InventoryRecord;
import com.ys.service.DrugsService;
import com.ys.service.WarehouseService;
import com.ys.vo.ResultVo;
import com.ys.vo.TreeVo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import sun.reflect.generics.tree.Tree;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/check")
public class ZInventoryCheckController {
    @Resource
    private DrugsService drugsService;
    @Resource
    private WarehouseService warehouseService;

    @Resource
    private InventoryMapper inventoryMapper;

    @Resource
    private InventoryRecordMapper inventoryRecordMapper;

    @GetMapping("/pandian")
    public ModelAndView index(){
        ModelAndView mav = new ModelAndView();
        mav.setViewName("kucun/kucunCheck");
        return mav;
    }

    @GetMapping("/searchName")
    public ResultVo searchName(String drugsName){
        List<Drugs> list = drugsService.searchDrugsName(drugsName);
        return ResultVo.success(list);
    }

    @PostMapping(value = "/updChaNum", produces = "application/json;charset=utf-8")
    public ResultVo updChaNum(@RequestBody Drugs[] chaNum,String comment){
        boolean isResult = drugsService.updChaNum(chaNum,comment);
        if (!isResult){
            return ResultVo.failure("修改失败...");
        }
        return ResultVo.success("修改成功...");
    }


    @GetMapping("/treeData")
    public ResultVo treeData(){
        List<TreeVo> list = warehouseService.searchAll();
        return ResultVo.success(list);
    }

    @GetMapping("/searchBitId")
    public ResultVo searchBitId(Integer bitId){
        List<Drugs> list = drugsService.searchBitId(bitId);
        return ResultVo.success(list);
    }

    @GetMapping("/searchRecord")
    public ResultVo searchRecord(Integer invRecordId){
        List<InventoryRecord> list = inventoryRecordMapper.findInvRecordId(invRecordId);
        return ResultVo.success(list);
    }

    @GetMapping("/searchInvent")
    public ResultVo searchInvent(){
        List<Inventory> list = inventoryMapper.findAll();
        return ResultVo.success(list);
    }
}
